feat(hermes): add on_pre_compress hook to preserve context before compression#870
Closed
pyrate-llama wants to merge 1 commit intovectorize-io:mainfrom
Closed
feat(hermes): add on_pre_compress hook to preserve context before compression#870pyrate-llama wants to merge 1 commit intovectorize-io:mainfrom
pyrate-llama wants to merge 1 commit intovectorize-io:mainfrom
Conversation
…pression When Hermes compresses its context window to save tokens, the original messages are summarized and the full text is discarded. This adds an on_pre_compress lifecycle hook that fires just before compression, capturing the last 10 user/assistant messages and persisting them to the Hindsight knowledge graph via retain(). The retain call runs in a background thread so it never blocks the compression pipeline. Messages are truncated to 500 chars each and tagged with [Pre-compression context] for easy identification. Requires hermes-agent >= 0.7.0 which supports the on_pre_compress hook. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nicoloboschi
requested changes
Apr 7, 2026
Collaborator
nicoloboschi
left a comment
There was a problem hiding this comment.
Hi, the official plugin now is in the Hermes repo: https://github.com/NousResearch/hermes-agent/blob/main/plugins/memory/hindsight/__init__.py
this one is gonna be discontinued soon, can you submit this change in there?
pyrate-llama
added a commit
to pyrate-llama/hermes-agent
that referenced
this pull request
Apr 7, 2026
…compression When Hermes compresses its context window, the original messages are summarised and discarded. This hook fires just before compression, capturing the last 10 user/assistant messages and persisting them to the Hindsight knowledge graph via retain(). Messages are tagged with '[Pre-compression context]' for easy identification and are retained with context='pre_compress' so they remain searchable via recall/reflect. The retain call runs in a background thread so it never blocks the compression pipeline. Closes vectorize-io/hindsight#870 (migrated from standalone plugin).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
on_pre_compresslifecycle hook to the Hermes integration that fires before context window compressionretain()Motivation
When Hermes compresses its context window to save tokens, the original messages are summarized and the full text is discarded. This means potentially valuable context is lost forever. By hooking into the compression lifecycle, we can preserve those messages in Hindsight's knowledge graph where they remain searchable via
recall()andreflect().This was inspired by ByteRover's
on_pre_compressimplementation, adapted to use Hindsight's syncretain()API.Details
[Pre-compression context]prefix for easy identificationon_pre_compresshookTest plan